//
//  SetupConfiguration.m
//  Rail
//
//  Created by hychen on 2018/2/25.
//  Copyright © 2018年 Hychen. All rights reserved.
//

#import "SetupConfiguration.h"

@implementation SetupConfiguration

SingletonM_lib(Tool)

- (void)setupSetting{
    
    [self prepareNetworkSetting];
    
    [self prepareThird];
    
    [self prepareAppSetting];
    
    [self prepareSDKSetting];
    
    [self prepareData];
    
}

- (void)prepareNetworkSetting{
    [MessageFactory getAppConfig].domain_url = Domain_Url;
    [MessageFactory getAppConfig].upload_url = UpLoad_Url;
    [MessageFactory getAppConfig].timeout = 15;
}

- (void)prepareThird{
    [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
}

- (void)prepareAppSetting{
    //白色状态栏
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
    //SVProgressHUD
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD setBackgroundColor:[UIColor blackColor]];
    [SVProgressHUD setMinimumDismissTimeInterval:1.2];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];
    
    // 不设置透明
    [[UINavigationBar appearance] setTranslucent:NO];
    
}

#pragma mark - 初始化第三方SDK
- (void)prepareSDKSetting{
    [self prepareBugly];
}

- (void)prepareBugly{
    [Bugly startWithAppId:BuglyKey];
}

#pragma mark - 初始化数据
- (void)prepareData{

}

#pragma mark - public method
- (CYLTabBarController *)setupTabBar{
    //初始化子控制器
    HomeViewController *firstViewController = [[HomeViewController alloc] init];
    UIViewController *firstNavigationController = [[BaseNavigationController alloc]
                                                   initWithRootViewController:firstViewController];
    
    InformationViewController *secondViewController = [[InformationViewController alloc] init];
    UIViewController *secondNavigationController = [[BaseNavigationController alloc] initWithRootViewController:secondViewController];
    
    FavCollectionViewController *thirdViewController = [[FavCollectionViewController alloc] init];
    UIViewController *thirdNavigationController = [[BaseNavigationController alloc] initWithRootViewController:thirdViewController];
    
    MineViewController *fourthViewController = [[MineViewController alloc] init];
    UIViewController *fourthNavigationController = [[BaseNavigationController alloc] initWithRootViewController:fourthViewController];
    
    //初始化TabBar
    CYLTabBarController *tabBarController = [[CYLTabBarController alloc] init];
    
    //配置子控制器
    NSDictionary *dict1 = @{
                            CYLTabBarItemTitle : @"首页",
                            CYLTabBarItemImage : @"app_home_n_ic",
                            CYLTabBarItemSelectedImage : @"app_home_p_ic",
                            };
    NSDictionary *dict2 = @{
                            CYLTabBarItemTitle : @"消息",
                            CYLTabBarItemImage : @"app_information_n_ic",
                            CYLTabBarItemSelectedImage : @"app_information_p_ic",
                            };
    NSDictionary *dict3 = @{
                            CYLTabBarItemTitle : @"收藏",
                            CYLTabBarItemImage : @"app_collect_n_ic",
                            CYLTabBarItemSelectedImage : @"app_collect_p_ic",
                            };
    NSDictionary *dict4 = @{
                            CYLTabBarItemTitle : @"我的",
                            CYLTabBarItemImage : @"app_me_n_ic",
                            CYLTabBarItemSelectedImage : @"app_me_p_ic",
                            };
    
    NSArray *tabBarItemsAttributes = @[dict1, dict2, dict3, dict4];
    tabBarController.tabBarItemsAttributes = tabBarItemsAttributes;
    
    NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
    normalAttrs[NSForegroundColorAttributeName] = Color_RGB(176, 176, 176);
    normalAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    
    // 选中状态下的文字属性
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSForegroundColorAttributeName] = Color_RGB(0, 193, 224);
    selectedAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    
    UITabBarItem *tabBar = [UITabBarItem appearance];
    [tabBar setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
    [tabBar setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    
    [tabBarController setViewControllers:@[
                                           firstNavigationController,
                                           secondNavigationController,
                                           thirdNavigationController,
                                           fourthNavigationController
                                           ]];
    return tabBarController;
}


@end
